package io.renren.entity;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.renren.common.utils.IntDexUtils;
import io.renren.param.NamePlateAliasParam;
import io.renren.param.RoomSaveParam;
import lombok.Data;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 会议室价签
 *
 * @author 1
 * @email 1@2.com
 * @date 2021-08-19 11:56:03
 */
@Data
@TableName("room_esl")
public class RoomEslEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 会议室id
     */
    private Long roomId;
    /**
     * 价签id
     */
    private String eslId;
    /**
     * 价签类型，door-门牌；namePlate-桌面铭牌
     */
    private String type;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 铭牌别名
     */
    private String alias;

    public static List<RoomEslEntity> convertFor(RoomSaveParam param, Long roomId) {
        List<RoomEslEntity> roomEslEntities = new ArrayList<>();

        //桌面铭牌
        final Date createTime = new Date();
        if (CollectionUtil.isNotEmpty(param.getNamePlateAliasParams())) {
            int i = 0;
            int aliasIndex = 1;
            String sysAlias = "";
            for (NamePlateAliasParam namePlateAliasParam : param.getNamePlateAliasParams()) {
                if (i % 2 == 0) {
                    sysAlias = param.getCorpId() + "_" + param.getName() + "_" + aliasIndex;
                    aliasIndex++;
                }

                RoomEslEntity roomEslEntity = new RoomEslEntity();
                /* fixme: */
                roomEslEntity.setEslId(IntDexUtils.DtoH(new BigInteger(namePlateAliasParam.getEslId())));
//                roomEslEntity.setAlias(namePlateAliasParam.getAlias());
                roomEslEntity.setAlias(sysAlias);
                roomEslEntity.setRoomId(roomId);
                roomEslEntity.setType("namePlate");
                roomEslEntity.setCreateTime(createTime);
                roomEslEntity.setUpdateTime(createTime);
                roomEslEntities.add(roomEslEntity);

                i++;
            }
        }


        //门牌
        RoomEslEntity roomEslEntity = new RoomEslEntity();
        roomEslEntity.setEslId(IntDexUtils.DtoH(new BigInteger(param.getDoorEslId())));
        roomEslEntity.setRoomId(roomId);
        roomEslEntity.setType("door");
        roomEslEntity.setCreateTime(createTime);
        roomEslEntity.setUpdateTime(createTime);
        roomEslEntities.add(roomEslEntity);

        return roomEslEntities;
    }

}
